package com.nuo.laboratory.dataStructure;

import java.util.Arrays;

/**
 * 环形指定大小队列
 * Your MyCircularQueue object will be instantiated and called as such:
 * MyCircularQueue obj = new MyCircularQueue(k);
 * boolean param_1 = obj.enQueue(value);
 * boolean param_2 = obj.deQueue();
 * int param_3 = obj.Front();
 * int param_4 = obj.Rear();
 * boolean param_5 = obj.isEmpty();
 * boolean param_6 = obj.isFull();
 */
public class MyCircularQueue {
    // 1 2 3 4 5 6
    int front;//队首指针
    int rear;//队尾指针
    int size;//队列大小
    int[] data;//顺序队列

    //构造器
    public MyCircularQueue(int size) {
        this.data = new int[size];
        this.size = size;
        this.front = -1;
        this.rear = -1;
    }

    public boolean enQueue(int value) {
        if (isFull()) {
            return false;
        }
        if (isEmpty()) {
            front = 0;
        }

        // 插入的下标
        rear = (rear + 1) % size;
        data[rear] = value;
        return true;
    }


    public boolean deQueue() {
        if (isEmpty()) {
            return false;
        }
        if (front == rear) {
            front = -1;
            rear = -1;
            return true;
        }
        // 往前移动一位
        front = (front + 1) % size;
        return true;
    }

    public int Front() {
        if (isEmpty()) {
            return -1;
        }
        return data[front];
    }

    public int Rear() {
        if (isEmpty()) {
            return -1;
        }
        return data[rear];
    }

    /**
     * 是否为空队列
     *
     * @return
     */
    public boolean isEmpty() {
        return front == -1;
    }


    /**
     * 满足队列已满
     *
     * @return
     */
    public boolean isFull() {
        return ((rear + 1) % size == front);
    }
}

class Solution {

    /**
     * 输入：n = 12
     * 输出：3
     * 解释：12 = 4 + 4 + 4
     */
    public int numSquares(int n) {
        int x = (int) Math.sqrt(n);
        int[] queue = new int[x];
        for (int i = 1; i <= x; i++) {
            queue[i - 1] = i * i;
        }
        System.out.println(x);
        System.out.println(Arrays.toString(queue));
        for (int i = queue.length - 1; i >= 0; i--) {

        }
        return x;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.numSquares(12);

    }
}

class HelloWorld {
    public void showNumber(int a, int b) {
        for (; a <= b; a++) {
            for (int i = 0; i <= Math.sqrt(b); i++) {
                if (i * i == a) {
                    System.out.println(a);
                }
            }
        }
    }

    public static void main(String[] args) {
        HelloWorld helloWorld = new HelloWorld();
        helloWorld.showNumber(0, 10);
    }
}

